
using System;
using System.Linq;
using Csla;
using Csla.Data;
using Csla.Security;
using Csla.Validation;

namespace HousingInfo.Library
{ 
	public partial class ForumNewsBO : Csla.BusinessBase<ForumNewsBO>
	{

		#region Authorization Rules
		protected override void AddAuthorizationRules()
		{
			//TODO: Define authorization rules in ForumNewsBO
			//AuthorizationRules.AllowRead(ForumNewIDProperty, "ForumNewsBOReadGroup");
			//AuthorizationRules.AllowRead(UserNameProperty, "ForumNewsBOReadGroup");
			//AuthorizationRules.AllowRead(CategoryIDProperty, "ForumNewsBOReadGroup");
			//AuthorizationRules.AllowRead(TitleProperty, "ForumNewsBOReadGroup");
			//AuthorizationRules.AllowRead(ForumNewsContentProperty, "ForumNewsBOReadGroup");
			//AuthorizationRules.AllowRead(UrlImageProperty, "ForumNewsBOReadGroup");
			//AuthorizationRules.AllowRead(CreatedDateProperty, "ForumNewsBOReadGroup");
			//AuthorizationRules.AllowRead(UpdatedDateProperty, "ForumNewsBOReadGroup");
			//AuthorizationRules.AllowRead(IsViolationProperty, "ForumNewsBOReadGroup");
			//AuthorizationRules.AllowRead(UserNameReportProperty, "ForumNewsBOReadGroup");
			//AuthorizationRules.AllowRead(NumberReportProperty, "ForumNewsBOReadGroup");
			//AuthorizationRules.AllowRead(ViewCountProperty, "ForumNewsBOReadGroup");

			//AuthorizationRules.AllowWrite(UserNameProperty, "ForumNewsBOWriteGroup");
			//AuthorizationRules.AllowWrite(CategoryIDProperty, "ForumNewsBOWriteGroup");
			//AuthorizationRules.AllowWrite(TitleProperty, "ForumNewsBOWriteGroup");
			//AuthorizationRules.AllowWrite(ForumNewsContentProperty, "ForumNewsBOWriteGroup");
			//AuthorizationRules.AllowWrite(UrlImageProperty, "ForumNewsBOWriteGroup");
			//AuthorizationRules.AllowWrite(CreatedDateProperty, "ForumNewsBOWriteGroup");
			//AuthorizationRules.AllowWrite(UpdatedDateProperty, "ForumNewsBOWriteGroup");
			//AuthorizationRules.AllowWrite(IsViolationProperty, "ForumNewsBOWriteGroup");
			//AuthorizationRules.AllowWrite(UserNameReportProperty, "ForumNewsBOWriteGroup");
			//AuthorizationRules.AllowWrite(NumberReportProperty, "ForumNewsBOWriteGroup");
			//AuthorizationRules.AllowWrite(ViewCountProperty, "ForumNewsBOWriteGroup");
		}

		protected static void AddObjectAuthorizationRules()
		{
			//TODO: Define object-level authorization rules of ForumNewsBO
			//AuthorizationRules.AllowCreate(typeof(ForumNewsBO), "ForumNewsBOCreateGroup"));
			//AuthorizationRules.AllowEdit(typeof(ForumNewsBO), "ForumNewsBOEditGroup"));
			//AuthorizationRules.AllowDelete(typeof(ForumNewsBO), "ForumNewsBODeleteGroup"));
		}
		#endregion //Authorization Rules
		private void AssignParentKey(HousingInfo.DataLinQ.ForumNew data)
		{
			 //data.ParentId = ReadProperty<ParentBO>(ParentBOProperty).Id;
		}

        #region Ham xoa tat ca cac tin comment theo id tin dien dan
        public static void DeleteAllForumsComment_ByForumNewsID(int forumNewsID)
        {
            using (var mgr = ContextManager<HousingInfo.DataLinQ.HousingInfoDataContext>
                        .GetManager(Database.HousingInfoConnection))
            {
                var resultcomment = from rowcomment in mgr.DataContext.ForumCommemts
                                    where rowcomment.ForumNewID == forumNewsID
                                    select rowcomment;
                foreach (var itemcomment in resultcomment)
                {
                    ForumCommentBO.DeleteForumCommentBO(itemcomment.ForumCommentID);
                }
                ForumNewsBO.DeleteForumNewsBO(forumNewsID);
            }

        }
        #endregion
    }
}
